#include <stdio.h>
#include "../air.hpp"
//-test-class-air------------------------------------------
//---------------------------------------------------------
int main(){
  printf("tests of class air are going to be written in 'class_air.txt'\n");
  FILE *fi;
  fi = fopen("class_air.txt","w+");
  fprintf(fi,"TEST: class air\n");
//---------------------------------------------------------
  fprintf(fi,"--upload-topology-from-file-without-class-air:\n");
  airline **als; //все ВТ в топологии аэропорта
  FILE *fs;
  fs = fopen("../../source.txt","r");
  if(fs == NULL){
    perror("Error opening file");
  }else{    
    char name[20],type[4],gps[1000];
    int als_dim; //кол-во ВТ в топологии
    fscanf(fs,"%i\n",&als_dim);
    printf("В топологии %d ВТ\n",als_dim);
    als = new airline*[als_dim];
    for(int i=0; i<als_dim; i++){
      fscanf(fs,"%s",name);
      fscanf(fs,"%s",type);
      fscanf(fs,"%s",gps);
      //разбор строки координат
      int count = 0;
      for(size_t j=0; j<strlen(gps); j++){
        if(gps[j] == ';') count++;
      }
      count *= 4;
      char *gps_tmp;
      vector gps_c(count);
      int indx = 0;
      gps_tmp = strtok(gps,",/;");
      while(gps_tmp != NULL){
        gps_c[indx] = atof(gps_tmp);
        indx++;
        gps_tmp = strtok(NULL,",/;");
      }
      //добавление очередной ВТ
      als[i] = new airline;
      als[i]->set_name(name);
      als[i]->set_sidstar(type);
      for(int k=0; k<count/4; k++){
        als[i]->add(als[i]->degmin_to_rad(gps_c[4*k],gps_c[4*k+1]),als[i]->degmin_to_rad(gps_c[4*k+2],gps_c    [4*k+3]),true);
      }
      als[i]->print();
    }
  }
  fclose(fs);
//---------------------------------------------------------
  fprintf(fi,"--upload-topology-from-file-with-class-air:\n");
  fprintf(fi,"---opening-source-file-in-main\n");
  air *berlin;
  berlin = new air;
  FILE *fc;
  fc = fopen("../../source.txt","r");
  berlin->get_topology(fc);
  berlin->print();
  fclose(fc);
//---------------------------------------------------------
  fprintf(fi,"--upload-topology-from-file-with-class-air:\n");
  fprintf(fi,"---opening-source-file-in-class-by-name\n");
  air *brln;
  brln = new air("../../source.txt");
  brln->print();
//---------------------------------------------------------
  fclose(fi);
  return 0;
}
